import java.util.Observable;

public class Buffer extends Observable{
	
	//----------------Arguments--------------------------------------------------------------------------
	
	private StringBuffer text;
	private int tailleTexte;
	private PressePapier PP;
	private IHM ihm;
	private Gardien gardien;
	
	//----------------Constructeur----------------------------------------------------------------------
	
	public Buffer(IHM ih){
		this.text = new StringBuffer();
		this.PP = new PressePapier();
		this.ihm = ih;
		this.gardien = new Gardien(this);
	}
	
	//----------------Methodes--------------------------------------------------------------------------
		
	public void inserer(String t, int debSel, int finSel)
	{
		this.text = this.text.replace(debSel, finSel, t);
		String strText = text.toString();
		setChanged(); 
	    notifyObservers(); 
	}
		
	public void coller(int debSel, int finSel)
	{	
		String textColler = PP.lire();
		this.text = this.text.replace(debSel, finSel, textColler);
		String strText = text.toString();
		setChanged(); 
	    notifyObservers(); 
	}
	
	public void copier(int debSel, int finSel)
	{
		String textCopier = this.text.substring(debSel, finSel).toString();
		PP.ecrire(textCopier);
	}

	public void supprimer(int debSel, int finSel) {
		this.text = this.text.delete(debSel, finSel);
		String strText = text.toString();
		setChanged(); 
	    notifyObservers(); 
	}
	
	public void retablir(Memento mem) {
		this.text.replace(0, text.length(), mem.getTextPrincipal()) ;
		PP.ecrire(mem.getTextBuffer());
		setChanged(); 
	    notifyObservers();	
	}
	
	public String getText() {
		return text.toString();
	}

	public Gardien getGardien() {
		return gardien;
	}
	
	public PressePapier getPP()
	{
		return this.PP;
	}
}
